struct Command{
virtual void call() const=0;
};
struct BankAccountCommand: Command{
BankAccount& account;
enum Action{ deposit, withdraw } action;
int amount;
BankAccountCommand(BankAccount& account, const Action action, const int amount): account(account), action(action), amount(amount) {}
};
void call() const override {
switch(action){
case deposit:
account.deposit(amount);
break;
case withdraw:
account.withdraw(amount);
break;
}
}
BankAccount ba;
Command cmd{ba, BankAccountCommand::deposit, 100};
cmd.call();